﻿<?php 
require_once("class.data.php");
class file_class
{
	private $each_page=15;
	private $all_num;
	private $all_page;
	function __construct()
	{
		$db=new data_class;
		$sql="SELECT id FROM file";
		$r_count=$db->query($sql);
		$k=0;
		while($r_count[$k]->id)
		{
			$k++;
		}
		$num=$k;
		if(!$num)
		{
			$this->all_num=0;
			$this->all_page=1;
		}
		else
		{
			$this->all_num=$num;	
			$this->all_page=@ceil($num/$this->each_page);
		}
	}
	function get_num()
	{
		return $this->all_num;
	}
	function get_all_page()
	{
		return $this->all_page;
	}
	function get_file($page)
	{
		$db=new data_class;
		$sql="SELECT * FROM file ORDER BY time DESC LIMIT ".(($page-1)*15).",15";
		$r=$db->query($sql);
		return $r;
	}
	function del($id)
	{
		$db=new data_class;
		$sql="DELETE FROM file WHERE id='".$id."'";
		$db->execute($sql);
	}
	function get_file_id($id)
	{
		$db=new data_class;
		$sql="SELECT * FROM file where id='".$id."'";
		$r=$db->query($sql);
		return $r;
	}
	function edit($id,$name,$description)
	{
		$db=new data_class;
		$sql="UPDATE file SET name='".$name."',description='".$description."' WHERE id='".$id."'";
		$db->execute($sql);
	}
}
?>